import socket
my_ip = socket.gethostbyname(socket.gethostname())
print(socket.gethostname())     # LAPTOP-9RU1PV3N
print(my_ip)       # 172.17.112.1

p = socket.socket(socket.AF_INET, socket.SOCK_STREAM)   # 两个参数表示的意思：(IPV4的地址，TCP连接)
p.connect((my_ip, 8080))  # 服务器的IP地址，端口号
while 1:
    msg = input('please input')     # msg为发送的信息
    # 防止输入空消息
    if not msg:
        continue
    p.send(msg.encode('utf-8'))  # 收发消息一定要二进制，记得编码
    if msg == '1':
        break
p.close()
